#include<stack>
using std::stack;

class MinStack {
public:
    stack<long> myStack; 
    long minValue;
    MinStack() {
        minValue = 0;
    }
    
    void push(int val) {
        if (myStack.empty()) {
            minValue = val;
            myStack.push(0);
            return;
        }
        long diff = val - minValue;
        myStack.push(diff);
        if (diff < 0) minValue = val;
    }
    
    void pop() {
        if (!myStack.empty()) {
            long diff = myStack.top();
            if (diff < 0) minValue = minValue - diff;
            myStack.pop();
        }
    }
    
    int top() {
        return int(myStack.top() + minValue);
    }
    
    int getMin() {
        return minValue;
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */